﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmartMD.DataModel.Entity;
using SmartMD.DataAccess.Service;
using System.Xml;
using SmartMD.Manager.Utils;
using Duoease.ContainerModel;

namespace SmartMD.Manager.Specimens
{
    /**
     * 类：模型维护
     * 
     * */
    public class ModelMaintain
    {
        public ModelMaintain()
        {
            CM = new ContainerModelView();
        }
        private static ModelMaintain inst = null;
        public static ModelMaintain getInstance()
        {
            if (inst == null)
            {
                inst = new ModelMaintain();             
            }
            return inst;
        }

        #region 模型属性
        private ContainerModelView _CM = null;
        public ContainerModelView CM
        {
            get { return _CM; }
            set
            {
                _CM = value;
            }
        }
        /// <summary>
        /// 标本位置
        /// </summary>
        private string _Position = "";
        public string Position
        {
            get { return _Position; }
            set { _Position = value; }
        }

        /// <summary>
        /// 标本所在行
        /// </summary>
        private int _row = 0;
        public int Row
        {
            get { return _row; }
            set { _row = value; }
        }

        /// <summary>
        /// 标本所作列
        /// </summary>
        private int _column = 0;
        public int Column
        {
            get { return _column; }
            set { _column = value; }
        }
        #endregion

        public void SaveSpecEntities(List<SpecEntity> specEntityList)
        {
            SpecEntity specEntity;
            //bool success =  DataServiceManager.SpecimensService.SaveSpecEntities(specEntityList);
            for (int i = 0; i< specEntityList.Count; i++)
            {
                specEntity = specEntityList[i];
                ContainerEntity containerEntity = DataServiceManager.ContainerService.GetContainerBySitecode(specEntity.SiteCode);
                ContainerModelEntity cme = DataServiceManager.ContainerModelService.GetObjectByName(containerEntity.ModelType);
                if (cme != null)
                {
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(CompressionHelper.DeCompressToString(cme.StyleFile));
                    CM.docmodel.Xml = doc;
                    //CM.SetModelState(specEntity.SiteCode, true);
                }
            }
        }

    }
}
